home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_09_02 / 9n02038a < prev    next >
Text File  |  1990-11-10  |  479b  |  32 lines

  1.  
  2. Listing 3.
  3.  
  4. /* random.c */
  5.  
  6. #define SL_RAND_MAX 32767
  7.  
  8. static long next = 1;
  9.  
  10. unsigned slrand()
  11. {
  12.      next = next * 1103515245 + 12345;
  13.      return((unsigned int) ((next / 65536) % 32768));
  14. }
  15.  
  16. slsrand(seed)
  17. unsigned seed;
  18. {
  19.      next = seed;
  20. }
  21.  
  22. /* return a random number in the range 0 .. (limit - 1) */
  23. int slrandom(limit)
  24. unsigned limit;
  25. {
  26.      long num;
  27.  
  28.      num = (long) slrand();
  29.      return((int) ((num * limit) / (1L + SL_RAND_MAX)));
  30. }
  31.  
  32.